﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using LinFu.AOP.Interfaces;

namespace BrainTechLLC
{
	public class AssertBeforeAfterWrapper : AroundMethodBase, IAroundInvoke
	{
		protected override void Execute(IInvocationContext context, CutpointType when, object returnValue)
		{
			object thisObject = context.Target;
			Type t = thisObject.GetType();
			AssertBeforeAfterAttribute[] attrs = context.TargetMethod.ReadAttribute<AssertBeforeAfterAttribute>();

			if (when == CutpointType.Before)
				attrs.ForEachAttribute(attr => attr.DoWorkBefore(context, thisObject, t));
			else
				attrs.ForEachAttribute(attr => attr.DoWorkAfter(context, thisObject, t));
		}
	}
}

